package com.attedu.jdbc;

/**
 * @author tune_the last
 * @date 2025/11/3 - 16:45
 */

import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.Statement;

/**
 * 要求：使用JDBC在tedu库下的user表中插入1条表记录
 */
public class Demo01JDBC {
    public static void main(String[] args) throws Exception {
        //1.加载数据库驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        //2.获取数据库连接对象
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8", "root", "ASD13579asd");
        //3.获取statement，创建SQL语句的执行对象
        Statement statement = connection.createStatement();
        String sql = "INSERT INTO user(username, password, nickname, age) VALUES ('蔡徐坤','kunkun123','坤坤' ,24)";
        //4.执行SQL语句
        statement.executeUpdate(sql);
        System.out.println("数据插入成功");
        //5.断开连接
        connection.close();
    }
}
